import React, { Component } from 'react'
import '../assets/css/login.css'
import {login as Login} from '../request/login'

export default class login extends Component {
    state={
        phone:'',
        password:'',
    }
    submit(){
        var sendData = {
            phone:this.state.phone,
            password:this.state.password
        }
        Login(sendData).then(res=>{
            if(res.code===200){
                console.log(res);
                this.setState({
                    phone:'',
                    password:''
                })
            }
            //保存登录凭证
            localStorage.setItem('loginData',JSON.stringify(res.list))
            this.props.history.push('/uncenter')
        })
    }
    
    render() {
        var {phone,password} = this.state
        return (
            <>
                <div class="page-title">会员登录</div>
                <div class="container">
                    <div class="logo"></div>
                    <div class="form">

                        <div class="form-group">
                            <input type="text" value={phone} onChange={e=>this.setState({phone:e.target.value})}placeholder="手机号" />
                        </div>
                        <div class="form-group">
                            <input type="password" 
                            value={password} onChange={e=>this.setState({password:e.target.value})}  placeholder="密码" />
                        </div>
                        <div class="form-group">
                            <button class="btn-gray" onClick={this.submit.bind(this)}>登录</button>
                        </div>
                    </div>
                </div>
            </>
        )
    }
}
